/**<
Exercise 11. Selection sort an array of integers.
 Show the array after each swap that takes place.
 Smallest to largest or largest to smallest
 */

#include<iostream>
using namespace std;

 void SelectionSort(){

     const int array_size = 9;
     int nArray[array_size] = {29, 1545, 30, 60, 20, 50, 126, 40, 10};

     //cycle through all elements in the array
     for(int i=0;i<array_size;i++){
        //search the remaining array for the lowest value vs the current value
        //note to switch largest to smallest, change 'i' to '0' for initial j
        for(int j=i;j<array_size;j++){
            //if the candidate array value of j is lower than ith value, switch them
            if (nArray[j] <= nArray[i]) swap(nArray[j],nArray[i]);
        }

        //show the array for each iteration through the loop
     cout << "Cycle(" << i << "): " ;
        for (int k=0; k<array_size;k++) cout << nArray[k] << ", ";
        cout << endl;
    }
 }
